/* istanbul ignore file */

import {
  Polygonal,
  Geometry,
  Polygon,
  MultiPolygon,
  LineString,
  MultiLineString,
  Feature,
  FeatureCollection,
} from '@nebula.gl/edit-modes';

function getPacManMultiPolygon(): MultiPolygon {
  return {
    type: 'MultiPolygon',
    coordinates: [
      [
        [
          [24.509897232055664, 70.43510308193534],
          [24.512774742872846, 70.43377246860858],
          [24.516506195068356, 70.43415455749883],
          [24.518051147460938, 70.43610904442177],
          [24.51444625854492, 70.43711495721077],
          [24.51023091718955, 70.43659663127778],
          [24.510509443918508, 70.43773315572952],
          [24.52198759777441, 70.43993098279594],
          [24.530351969222917, 70.43979023142828],
          [24.540882110595703, 70.4375747865055],
          [24.541053771972656, 70.42898001001919],
          [24.536590576171875, 70.4300150246936],
          [24.531955718994137, 70.4290375122142],
          [24.526805877685547, 70.43047501433419],
          [24.520397743119403, 70.4288568086563],
          [24.51496124267578, 70.43007252396679],
          [24.510159571030567, 70.42876569452596],
          [24.509897232055664, 70.43510308193534],
        ],
        [
          [24.52646255493164, 70.43708621753503],
          [24.526634216308594, 70.43610904442177],
          [24.527664184570312, 70.43484439783438],
          [24.530067443847653, 70.43472942606802],
          [24.532299041748047, 70.43472942606802],
          [24.534187316894528, 70.43501685426682],
          [24.535045623779297, 70.43576414859652],
          [24.535388946533203, 70.43628149014363],
          [24.53521728515625, 70.43708621753503],
          [24.534358978271484, 70.43760352549158],
          [24.53144073486328, 70.43812082030453],
          [24.53075408935547, 70.43806334375216],
          [24.52646255493164, 70.43708621753503],
        ],
      ],
      [
        [
          [24.434452056884766, 70.43858062688211],
          [24.435197322726804, 70.44421917386198],
          [24.449372330164838, 70.44991233297016],
          [24.475994110107422, 70.44949798144461],
          [24.492816925048828, 70.44283334545445],
          [24.46208953857422, 70.44119557930743],
          [24.482173919677734, 70.4325448391651],
          [24.46349686309326, 70.4308843242287],
          [24.446296691894528, 70.43248734687127],
          [24.434452056884766, 70.43858062688211],
        ],
      ],
      [
        [
          [24.475650787353512, 70.4397300978937],
          [24.483890533447266, 70.44007492654139],
          [24.485607147216797, 70.43789091312142],
          [24.478740692138672, 70.43708621753503],
          [24.475650787353512, 70.4397300978937],
        ],
      ],
    ],
  };
}

function getPacManPolygon(): Polygon {
  return {
    type: 'Polygon',
    coordinates: [
      [
        [24.434452, 70.43858],
        [24.435198, 70.44422],
        [24.449373, 70.44991],
        [24.475994, 70.4495],
        [24.492817, 70.44283],
        [24.46209, 70.44119],
        [24.482174, 70.43255],
        [24.463497, 70.430885],
        [24.446297, 70.43249],
        [24.434452, 70.43858],
      ],
    ],
  };
}

export function createPolygonAroundNullIsland(): Polygon {
  return {
    type: 'Polygon',
    coordinates: [
      [
        [1, 1],
        [-1, 1],
        [-1, -1],
        [1, -1],
        [1, 1],
      ],
    ],
  };
}

export function createPolygonRightOfNullIsland(): Polygon {
  return {
    type: 'Polygon',
    coordinates: [
      [
        [2, 2],
        [0, 2],
        [0, -2],
        [2, -2],
        [2, 2],
      ],
    ],
  };
}

export function createPolygonFarRightOfNullIsland(): Polygon {
  return {
    type: 'Polygon',
    coordinates: [
      [
        [4, 1],
        [2, 1],
        [2, -1],
        [4, -1],
        [4, 1],
      ],
    ],
  };
}

export function createRandomPolygonal(): Polygonal {
  return Math.random() > 0.5 ? getPacManMultiPolygon() : getPacManPolygon();
}

export function createRandomPolygon(): Polygon {
  return getPacManPolygon();
}

export function createRandomMultiPolygon(): MultiPolygon {
  return getPacManMultiPolygon();
}

export function createRandomLineString(): LineString {
  return {
    type: 'LineString',
    coordinates: [
      [1, 2],
      [2, 3],
    ],
  };
}

export function createRandomMultiLineString(): MultiLineString {
  return {
    type: 'MultiLineString',
    coordinates: [
      [
        [1, 2],
        [2, 3],
        [3, 4],
      ],
      [
        [4, 5],
        [5, 6],
      ],
    ],
  };
}

export function wrapInFeature(geometry: Geometry): Feature {
  return {
    type: 'Feature',
    properties: { name: `name-${Math.round(Math.random() * 100)}` },
    geometry,
  } as Feature;
}

export function createRandomFeature(): Feature {
  return {
    type: 'Feature',
    properties: {},
    geometry: createRandomPolygon(),
  };
}

export function createRandomFeatureCollection(): FeatureCollection {
  return {
    type: 'FeatureCollection',
    properties: {
      name: 'Pac-Man Group',
    },
    features: [
      {
        type: 'Feature',
        properties: {
          name: 'Pac-Man 1',
        },
        geometry: {
          type: 'MultiPolygon',
          coordinates: [
            [
              [
                [24.435197322726804, 70.44421917386198],
                [24.449372330164838, 70.44991233297016],
                [24.475994110107422, 70.44949798144461],
                [24.492816925048828, 70.44283334545445],
                [24.46208953857422, 70.44119557930743],
                [24.435197322726804, 70.44421917386198],
              ],
            ],
            [
              [
                [24.475650787353512, 70.4397300978937],
                [24.483890533447266, 70.44007492654139],
                [24.485607147216797, 70.43789091312142],
                [24.478740692138672, 70.43708621753503],
                [24.475650787353512, 70.4397300978937],
              ],
            ],
          ],
        },
      },
      {
        type: 'Feature',
        properties: {
          name: 'Pac-Man Ghost',
        },
        geometry: {
          type: 'Polygon',
          coordinates: [
            [
              [24.509897232055664, 70.43510308193534],
              [24.512774742872846, 70.43377246860858],
              [24.516506195068356, 70.43415455749883],
              [24.518051147460938, 70.43610904442177],
              [24.51444625854492, 70.43711495721077],
              [24.51023091718955, 70.43659663127778],
              [24.510509443918508, 70.43773315572952],
              [24.52198759777441, 70.43993098279594],
              [24.530351969222917, 70.43979023142828],
              [24.540882110595703, 70.4375747865055],
              [24.541053771972656, 70.42898001001919],
              [24.536590576171875, 70.4300150246936],
              [24.531955718994137, 70.4290375122142],
              [24.526805877685547, 70.43047501433419],
              [24.520397743119403, 70.4288568086563],
              [24.51496124267578, 70.43007252396679],
              [24.510159571030567, 70.42876569452596],
              [24.509897232055664, 70.43510308193534],
            ],
            [
              [24.52646255493164, 70.43708621753503],
              [24.526634216308594, 70.43610904442177],
              [24.527664184570312, 70.43484439783438],
              [24.530067443847653, 70.43472942606802],
              [24.532299041748047, 70.43472942606802],
              [24.534187316894528, 70.43501685426682],
              [24.535045623779297, 70.43576414859652],
              [24.535388946533203, 70.43628149014363],
              [24.53521728515625, 70.43708621753503],
              [24.534358978271484, 70.43760352549158],
              [24.53144073486328, 70.43812082030453],
              [24.53075408935547, 70.43806334375216],
              [24.52646255493164, 70.43708621753503],
            ],
          ],
        },
      },
      {
        type: 'Feature',
        properties: {
          name: 'Pac-Man 2',
        },
        geometry: {
          type: 'Polygon',
          coordinates: [
            [
              [24.434452056884766, 70.43858062688211],
              [24.435197322726804, 70.44421917386198],
              [24.46208953857422, 70.44119557930743],
              [24.482173919677734, 70.4325448391651],
              [24.46349686309326, 70.4308843242287],
              [24.446296691894528, 70.43248734687127],
              [24.434452056884766, 70.43858062688211],
            ],
          ],
        },
      },
    ],
  };
}
